/**
 * 
 */


import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.furschina.model.User;

/**
 * @author iday
 *
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:/spring-test.xml"})
public class UserDaoTestCase {
	@Autowired
	private UserDao dao;
	private List<User> list = new ArrayList<User>();

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		User u = new User();
		u.setEmail("f5d@tom.com");
		u.setUsername("iday");
		dao.create(u);
		list.add(u);
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
		dao.deleteAll(list);
		list.clear();
	}

	/**
	 * Test method for {@link com.furschina.dao.UserDao#getByName(java.lang.String)}.
	 */
	@Test
	public void testGetByName() {
		User u = dao.getByName("iday");
		assertEquals("f5d@tom.com", u.getEmail());
	}

	/**
	 * Test method for {@link com.furschina.dao.UserDao#getByEmail(java.lang.String)}.
	 */
	@Test
	public void testGetByEmail() {
		User u = dao.getByEmail("f5d@tom.com");
		assertEquals("iday", u.getUsername());
	}

}
